/* QAD_OperationsAccountingReport.p - Report Proxy Template                                       */
/* Copyright 1986-2011 QAD Inc., Santa Barbara, CA, USA.                      */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Id:: QAD_TransactionsAccountingReport.p 1046 2010-09-10 09:08:19Z jvz  $: */
/*                                                                            */
/* Report matches legacy !!old.p!! for use by QAD Reporting Framework.        */
/*                                                                            */

{mfsubdirs.i}
{{&US_BBI}mfdeclre.i}
{{&US_BBI}gplabel.i}

{com/qad/shell/report/dsReportRequest.i}
{com/qad/shell/report/ReportConstants.i}

/*============================================================================*/
/* ****************************  TEMP TABLES  ******************************* */
/*============================================================================*/

/* TEMP-TABLE DEFINITION BLOCK */

define temp-table tt_op_hist no-undo like op_hist
   field wo_line       like wo_mstr.wo_line
   field opgl_gl_ref   like opgl_det.opgl_gl_ref
   field opgl_dr_acct  like opgl_det.opgl_dr_acct
   field opgl_dr_sub   like opgl_det.opgl_dr_sub
   field opgl_dr_cc    like opgl_det.opgl_dr_cc
   field opgl_dr_proj  like opgl_det.opgl_dr_proj
   field opgl_cr_acct  like opgl_det.opgl_cr_acct
   field opgl_cr_sub   like opgl_det.opgl_cr_sub
   field opgl_cr_cc    like opgl_det.opgl_cr_cc
   field opgl_gl_amt   like opgl_det.opgl_gl_amt
   field glrefid       like glt_det.glt_dy_num
   field ptal_alt_part like ptal_mstr.ptal_alt_part
   field mfgtype       as   character
   field desc1         like pt_mstr.pt_desc1
   field desc2         like pt_mstr.pt_desc2
   field disp_part     as   logical
   field disp_line     as   logical
   field unique_id     as   integer
.

define temp-table ttGeneralLedgerDetail no-undo like tt_gltw_wkfl
   field dr_amt     like glt_det.glt_amt
   field cr_amt     like glt_det.glt_amt
   field amt_format as   character
   field unique_id  as   integer
.

define temp-table ttReportOptions no-undo
   field ordertype as   character
   field tr_yn     like mfc_ctrl.mfc_logical
   field gl_yn     like mfc_ctrl.mfc_logical
.

define dataset dsReportResults for tt_op_hist, ttGeneralLedgerDetail, ttReportOptions.

/*============================================================================*/
/* *****************************  MAIN BLOCK  ******************************* */
/*============================================================================*/
define input parameter runReport    as logical no-undo.
define input parameter reportHandle as handle  no-undo.
define input parameter dataset      for dsReportRequest.
define output parameter dataset-handle phReportResults.

{com/qad/shell/report/reporting.i}

define variable vhDS as handle    no-undo.

empty temp-table tt_op_hist            no-error.
empty temp-table ttGeneralLedgerDetail no-error.
empty temp-table ttReportOptions       no-error.

for first ttReportRequest no-lock:

   vhDS = dataset dsReportResults:handle.
   run FillMetaData in reportHandle(
      vhDS, "QAD_OperationsAccountingReport.meta.xml").

   run SetReportMetaData (input reportHandle).

   if runReport then do:
      run RunReport
         (output dataset-handle phReportResults).
   end.

end.

PROCEDURE SetReportMetaData:

   define input parameter  ipReportHandle as handle.

   /*
   run SetFieldMetaParameter in ipReportHandle(
         "ttCoByProductsCostRpt", "si_site", "DefaultValue", site).
   */

END PROCEDURE. /* PROCEDURE ModifyMetaData */

/* DATA RETRIEVING LOGIC BLOCK */
PROCEDURE RunReport:

   define output parameter dataset-handle phReportResults.

   /* RETRIEVE THE DATA FROM DATABASE */
   define variable queryString   as character no-undo.
   define variable hMainQuery    as handle    no-undo.
   define query    MainQuery     for so_mstr.

   assign
      hMainQuery           = query MainQuery:handle.

   queryString = "for each so_mstr no-lock where so_domain = "
                  + quoter(global_domain).

   run AddAllConditions in reportHandle
      ("so_mstr", input-output queryString).

   queryString = queryString + ":".

   hMainQuery:query-prepare(queryString).
   hMainQuery:query-open().
   hMainQuery:get-next().

   repeat while not hMainQuery:query-off-end:

      hMainQuery:get-next().
   end. /* REPEAT QUERY */

   hMainQuery:query-close().
   delete object hMainQuery.
   phReportResults = dataset dsReportResults:handle.

END PROCEDURE.
